package com.yan.activity;


import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.yan.R;


public class GalleryUpdater extends MyAsyncTask<Article, Void, List<Integer>> {
	private static final String TAG = "IMAGE_VIEW_UPDATER";
	private Article mCurrentArticle;
	private BetterGallery mGallery;
	private Context mContext;
	
	public GalleryUpdater(BetterGallery g, Article article, Context c){
		mContext=c;
		mCurrentArticle = article;
		mGallery = g;
		
	}
	
	@Override
	protected  List<Integer> doInBackground(Article... params) {
		 List<Integer> imageList = null;
		try 
		{
			 imageList=loadImageList(params[0]);

		} 
		catch (Exception e) 
		{
			Debug.debugWarning(TAG, "Exception : " +params[0]);
			e.printStackTrace();
		} 
		
		DataManager.getInstance().addImageList(params[0], imageList);
		return imageList;
	}
	 
	@Override
    protected void onPostExecute(List<Integer> result) {
		if(mGallery == null || result == null)
			return;
		
		if (((String)mGallery.getTag()) == mCurrentArticle.getLink()){
			mGallery.setAdapter(new ImageAdapter(mContext, result));
			mGallery.setSpacing(5);
			mGallery.setSelection(mGallery.getCount()-1,true);
		}		
    }
	
	
    List<Integer> loadImageList(Article mCurrentarticle){
    	  
    	  
        List<Integer> imageList=new ArrayList<Integer> ();
        imageList.clear();
     
    
       if(mCurrentarticle.getDescription().toLowerCase().contains("bluetooth"))
           imageList.add(R.drawable.bluetooth);
       if(mCurrentarticle.getDescription().toLowerCase().contains("wifi"))
           imageList.add(R.drawable.wifi);
       if(mCurrentarticle.getDescription().toLowerCase().contains("android"))
           imageList.add(R.drawable.android);
       if(mCurrentarticle.getDescription().toLowerCase().contains("camera"))
           imageList.add(R.drawable.camera);
       if(mCurrentarticle.getDescription().toLowerCase().contains("usb"))
           imageList.add(R.drawable.usb);
       if(mCurrentarticle.getDescription().toLowerCase().contains("arduino"))
           imageList.add(R.drawable.arduino);
       if(mCurrentarticle.getDescription().toLowerCase().contains("raspberry pi"))
           imageList.add(R.drawable.raspberry_pi);
       if(mCurrentarticle.getDescription().toLowerCase().contains("infrared"))
           imageList.add(R.drawable.infrared);
       if(mCurrentarticle.getDescription().toLowerCase().contains("ioio"))
           imageList.add(R.drawable.ioio);
       if(mCurrentarticle.getDescription().toLowerCase().contains("drone")||mCurrentarticle.getDescription().toLowerCase().contains("helicopter"))
           imageList.add(R.drawable.drone);

          	
	   return imageList;
    }
    

    
    
    
}
